﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YAPL.Language.Ast.Utils;

namespace YAPL.Language.Ast {
	/// <summary>
	/// Represents function parameter
	/// </summary>
	public class ParameterExpression : Expression {
		private readonly VariableExpression _variable;
		private readonly Expression _defaultValue;

		public ParameterExpression(ExpressionType nodeType, Type type, VariableExpression variable, Expression defaultValue) : base(nodeType, type) {
			_variable = variable;
			_defaultValue = defaultValue;
		}

		public ParameterExpression(ExpressionType nodeType, Type type, bool canRead, bool canWrite, VariableExpression variable, Expression defaultValue)
			: base(nodeType, type, canRead, canWrite) {
			_variable = variable;
			_defaultValue = defaultValue;
		}

		[Descendant(AstVisit.BeforeCurrent, Priority = 0)]
		public VariableExpression Variable {
			get { return _variable; }
		}

		[Descendant(AstVisit.BeforeCurrent, Priority = 1)]
		public Expression DefaultValue {
			get { return _defaultValue; }
		}

		public override bool NodeEquals(Expression other) {
			return other is ParameterExpression;
		}

		public override bool RewriteChild(Expression child, Expression newExpression) {
			throw new System.NotImplementedException();
		}
	}
}
